package easyjava.hibernate.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import easyjava.hibernate.bean.StudentStatus;

public class StudentStatusDao {
	private Session session;
	public StudentStatusDao(Session session ){
		this.session=session;
	}
	
	public List<StudentStatus> list(){
		Query<StudentStatus> query =session.createQuery("from StudentStatus",StudentStatus.class);
		return query.getResultList();
	}
	public StudentStatus getStudentStatusById(int id){
		return session.get(StudentStatus.class, id);
	}
	
	public void insert(StudentStatus studentStatus) {
		Transaction tx = session.beginTransaction();
		try {

			session.save(studentStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
	}
	public void update(StudentStatus studentStatus){
		Transaction tx = session.beginTransaction();
		try {

			session.update(studentStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}
	public void delete(StudentStatus studentStatus){
		Transaction tx = session.beginTransaction();
		try {
			
			session.delete(studentStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}

}
